#include <stdio.h>
#include <assert.h>

#include "stack.h"

void test();

int main()
{
	test();
	printf("Tests OK!");
	return 0;
}

void test()
{
	// Default constructor
	Stack s = Stack();
	assert( s.size() == 0 );

	// Parameterized constructor
	s = Stack( 10 );
	assert( s.size() == 0 );

	// Push single value
	s.push( 5 );
	assert( s.size() == 1 );

	// Push several values
	s.push( 7 );
	s.push( 10 );
	assert( s.size() == 3 );

	// Push multiple values
	s = Stack();
	for( int i=0; i<10; i++ )
		s.push(i);
	assert( s.size() == 10 );

	// Pop single value
	s.pop();
	assert( s.size() == 9 );

	// Pop multiple
	for( int i=0; i<9; i++ )
		s.pop();
	assert( s.size() == 0 );

	// Push and pop values
	s = Stack();
	s.push(1);
	s.push(10);
	s.push(100);
	int v = s.pop();
	assert( v == 100 );
	v = s.pop();
	assert( v == 10 );
	v = s.pop();
	assert( v == 1 );

	// Empty check
	s = Stack();
	s.push( 5 );
	assert( !s.empty() );
	s.pop();
	assert( s.empty() );

	// Copy constructor check
	Stack s1 = Stack();
	s1.push(5);
	Stack s2 = s1;
	assert( s2.size() == 1 );
	v = s2.pop();
	assert( v == 5 );
	assert( s1.size() == 1 );
	assert( s2.size() == 0 );

	// Assignment operator check
	s1 = Stack();
	s2 = Stack();
	s1.push( 5 );
	assert( s2.size() == 0 );
	s2 = s1;
	assert( s2.size() == 1 );
	v = s2.pop();
	assert( v == 5 );
	assert( s1.size() == 1 );
	assert( s2.size() == 0 );
}
